using System;
using System.Collections;
using System.Drawing;
using SdlDotNet.Core;
using SdlDotNet.Graphics;
using SdlDotNet.Graphics.Primitives;
using SpaceTrader.Core.GameObjects;

namespace Core.GameObjects
{
    public class Player : GameObject
    {
        public Player(int x, int y) : base(x, y)
        {
        }

        public Player(int x, int y, string name) : base(x, y, name)
        {
        }

        public override Surface Render()
        {
            Surface surf = new Surface(30, 30);
            surf.Draw(GetPolygon(), ForeColor, true, true);

            return surf;
        }

        protected new Polygon GetPolygon()
        {
            ArrayList Points = new ArrayList(3);
            Vector Center = new Vector(new Point(15, 15));
            Vector Pixel = Vector.FromDirection(Rotation, 15);

            Pixel = Pixel + Center;
            Points.Add(Pixel.Point);

            Pixel = Vector.FromDirection(Rotation + 135, 15) + Center;
            Points.Add(Pixel.Point);

            Pixel = Vector.FromDirection(Rotation + 225, 15) + Center;
            Points.Add(Pixel.Point);

            return new Polygon(Points);
        }

        public override string ToString()
        {
            string[] Status = {
                                  Position.ToString(),
                                  Rotation.ToString(),
                                  Thrust.ToString(),
                                  Throttle.ToString()
                              };

            return String.Format("Player ( Position:{0}, Rotation: {1}, Thrust: {2}, Throttle: {3} )", Status);
        }

        public Projectile Fire()
        {
            Projectile bullet = new Projectile(Position.X, Position.Y);
            bullet.Rotation = Rotation;

            return bullet;
        }
    }
}